class Solution(object):
    def miceAndCheese(self, reward1, reward2, k):
        """
        :type reward1: List[int]
        :type reward2: List[int]
        :type k: int
        :rtype: int
        """
        n = len(reward1)
        # 创建一个列表，存储每个奶酪的reward1和reward2的差值，以及索引
        diff = []
        for i in range(n):
            diff.append((reward1[i] - reward2[i], i))

        # 按照差值从大到小排序
        diff.sort(reverse=True, key=lambda x: x[0])

        total = 0
        # 前k个选reward1，其余的选reward2
        selected_indices = set()
        for i in range(k):
            idx = diff[i][1]
            total += reward1[idx]
            selected_indices.add(idx)

        for i in range(n):
            if i not in selected_indices:
                total += reward2[i]

        return total